class Alg<T extends Comparable<T>> {
    public T findMax(T[] array) {
        T max = array[0];
        for (int i = 1; i < array.length; i++) {
            if(max.compareTo(array[i]) < 0) {   //报错原因：是引用类型，不能直接比较
                max = array[i];
            }
        }
        return max;
    }
}

class Person implements Comparable<Person>{
    public int age;
    public Person(int age) {
        this.age = age;
    }

    @Override
    public int compareTo(Person o) {
        return this.age - o.age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "age=" + age +
                '}';
    }
}

class TestDemo2<E extends Number> {   //限定泛型上界，E只能是Number子类或本身（但没有下界）

}


public class Test2 {
    public static void main(String[] args) {
        Alg3 alg3 = new Alg3();
        Integer[] array = {1,2,3,4};

    }



    public static void main4(String[] args) {
        Integer[] array = {1,2,3,4};
        Integer ret = Alg2.<Integer>findMax(array);
        System.out.println(ret);
    }

    public static void main3(String[] args) {
        Alg<Person> alg = new Alg<>();
        Person[] people = {new Person(10),new Person(18)};

    }
    public static void main2(String[] args) {
        Alg<Integer> alg = new Alg<>();
        Integer[] Array = {1,2,3,4};
        Integer ret = alg.findMax(Array);
        System.out.println(ret);
     }
}
